module Display {
	export class BasicDisplay extends egret.DisplayObjectContainer {
		private _txInfo:egret.TextField;
		private _bgInfo:egret.Shape;

		/**
		 * 构造函数
		 * 监听添加到舞台事件
		 */
		public constructor() {
			super();
			this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddedToStage,this);
		}

		/**
		 * 添加到舞台监听器
		 * 加载图片 
		 * @param evt:Event
		 */
		private onAddedToStage(evt:egret.Event):void{
			var imgLoader:egret.ImageLoader=new egret.ImageLoader;
			imgLoader.once(egret.Event.COMPLETE,this.imgLoaderHandler,this);
			imgLoader.load("resource/egret_icon.png");
		}

		/**
		 * 图片加载监听器
		 * @param evt:Event
		 */
		private imgLoaderHandler(evt:egret.Event):void{
			//显示图片
			var bmd:egret.BitmapData=evt.currentTarget.data as egret.BitmapData;
			var bird:egret.Bitmap=new egret.Bitmap(bmd);
			this.addChild(bird);
			bird.anchorOffsetX=bird.width*.5;
			bird.anchorOffsetY=bird.height*.5;
			bird.x=this.stage.stageWidth/2;
			bird.y=this.stage.stageHeight/2;
			//提示信息
			this._txInfo=new egret.TextField;
			this._txInfo.size=28;
			this._txInfo.x=50;
			this._txInfo.y=50;
			this._txInfo.textAlign=egret.HorizontalAlign.LEFT;
			this._txInfo.textColor=0xff0000;
			this._txInfo.lineSpacing=6;
			this._txInfo.multiline=true;
			this._txInfo.text="轻触屏幕调整显示对象位置";
			this.addChild(this._txInfo);
			//背景
			this._bgInfo=new egret.Shape();
			this._bgInfo.graphics.clear();
			this._bgInfo.graphics.beginFill(0xffffff,.5);
			this._bgInfo.x=this._txInfo.x;
			this._bgInfo.y=this._txInfo.y;
			this._bgInfo.graphics.drawRect(0,0,this._txInfo.width,this._txInfo.height);
			// this._bgInfo.graphics.drawRect(0,0,this.stage.stageWidth,this.stage.stageHeight);
			this._bgInfo.graphics.endFill();
			egret.log("numChildren:",this.numChildren);
			this.addChildAt(this._bgInfo,this.numChildren);	
			egret.log("bird index:",this.$children.indexOf(bird));
			egret.log("text index:",this.$children.indexOf(this._txInfo));		
			egret.log("bg index:",this.$children.indexOf(this._bgInfo));
			//添加鼠标事件监听器
			this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,(evt:egret.TouchEvent)=>{
				bird.x=evt.localX;
				bird.y=evt.localY;
			},this);
		}
	}
}
